package com.smartfactory.sail.controller;


import com.ada.base.common.ApiResponse;
import com.ada.base.common.ControllerResponse;
import com.smartfactory.sail.config.OperRecord;
import com.smartfactory.sail.entity.Logistics;
import com.smartfactory.sail.entity.OrderLogistics;
import com.smartfactory.sail.service.ILogisticsService;
import com.smartfactory.sail.service.IOrderItemService;
import com.smartfactory.sail.vo.logistics.LogisticsResp;
import com.smartfactory.sail.vo.order.OrderLogisticsReq;
import com.smartfactory.sail.vo.order.OrderLogisticsResp;
import com.smartfactory.sail.vo.order.PackingDetailResp;
import com.smartfactory.sail.vo.order.PackingListResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 物流信息表 前端控制器
 * </p>
 *
 * @author 王巨壁
 * @since 2019-07-24
 */
@Api(tags = "物流相关")
@RestController
@RequestMapping("/logistics")
public class LogisticsController extends ControllerResponse {

    private ILogisticsService iLogisticsService;
    private IOrderItemService iOrderItemService;

    public LogisticsController(ILogisticsService iLogisticsService, IOrderItemService iOrderItemService) {
        this.iLogisticsService = iLogisticsService;
        this.iOrderItemService = iOrderItemService;
    }

    @OperRecord(content = "客户已确认收货",level = 1)
    @ApiOperation(value = "确认收货", notes = "确认收货")
    @GetMapping("/confirm/{logisticsId}")
    public ApiResponse<Object> confirmLogistics(@PathVariable("logisticsId") long logisticsId) {
        return ok(iLogisticsService.confirmLogistics(logisticsId));
    }

    @ApiOperation(value = "根据custId找物流单列表", notes = "根据custId找物流单列表")
    @GetMapping("/list/{custId}")
    public ApiResponse<List<Logistics>> listLogistics(@PathVariable("custId") long custId) {
        return ok(iLogisticsService.listLogistics(custId));
    }

    @ApiOperation(value = "根据logisticsId找物流单内产品列表", notes = "根据logisticsId找物流单内产品列表")
    @GetMapping("/detail/{logisticsId}")
    public ApiResponse<LogisticsResp> detailLogistics(@PathVariable("logisticsId") long logisticsId) {
        return ok(iLogisticsService.detailLogistics(logisticsId));
    }

    @OperRecord(content = "生成物流单",level = 1)
    @ApiOperation(value = "生成物流单", notes = "生成物流单")
    @PostMapping
    public ApiResponse<Object> saveLogistics(@RequestBody OrderLogisticsReq orderLogisticsReq) {
        return ok(iLogisticsService.saveLogistics(orderLogisticsReq));
    }

    @GetMapping("/logistics/{orderId}")
    @ApiOperation(value = "根据订单id查找物流详情", notes = "根据订单id查找物流详情")
    public ApiResponse<List<OrderLogisticsResp>> findLogistics(@PathVariable("orderId") long orderId) {
        return ok(iLogisticsService.findLogistics(orderId));
    }

    @OperRecord(content = "申请发货",level = 1)
    @GetMapping("/{orderId}/{itemId}")
    @ApiOperation(value = "订销-》（申请发货）", notes = "订销-》（申请发货）")
    public ApiResponse<PackingListResp> findOrderItem(@PathVariable("orderId") long orderId, @PathVariable("itemId") long itemId) {
        return ok(iOrderItemService.findOrderItem(orderId, itemId));
    }

    @OperRecord(content = "申请发货",level = 1)
    @PostMapping("/request")
    @ApiOperation(value = "申请发货", notes = "申请发货")
    public ApiResponse<Boolean> requestLogistics(@RequestBody List<OrderLogistics> logistics) {
        return ok(iLogisticsService.requestLogistics(logistics));
    }


    @GetMapping("/cust/{custId}")
    @ApiOperation(value = "根据客户id查找发货详情", notes = "根据客户id查找发货详情")
    public ApiResponse<List<PackingDetailResp>> packingList(@PathVariable("custId") long custId) {
        return ok(iOrderItemService.packingDetail(custId));
    }

    @OperRecord(content = "发货",level = 1)
    @GetMapping("/{custId}/pack")
    @ApiOperation(value = "发货", notes = "发货")
    public ApiResponse<List<PackingDetailResp>> packing(@PathVariable("custId") long custId) {
        return ok(iOrderItemService.packing(custId));
    }


    @GetMapping("companys")
    @ApiOperation(value = "快递公司名称", notes = "快递公司名称")
    public ApiResponse<List<String>> companys() {
        return ok(iLogisticsService.companys());
    }

   /* @HeaderWrapper(OrderSendGoodsEnum.class)
    @ApiOperation(value = "发货列表 分页|currentPage|size|sortType|sortField 必传", notes = "发货列表 分页|currentPage|size|sortType|sortField 必传")
    @PostMapping("deliverGoodsList/{currentPage}/{size}/{sortType}/{sortField}")
    public ApiResponse<IPage<ListOrderItemInfoResp>> deliverGoodsList(@RequestBody Map<String, Object> queryParam,
                                                                      @PathVariable("currentPage") Long currentPage,
                                                                      @PathVariable("size") Integer size,
                                                                      @PathVariable("sortType") Integer sortType,
                                                                      @PathVariable("sortField") String sortField) {
        PageParam pageParam = new PageParam(currentPage, size, sortType, sortField);
        return ok(iOrderService.getSendGoodsList(pageParam, queryParam));
    }*/
}
